﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using RegisterationCommon.Common;
using RegisterationCommon.Student;
using System.Text;
using RegisterationCommon.School;
using RegisterationCommon.Notice;
using RegisterationCommon.Contrast;
using System.IO;
using System.Configuration;
using RegisterationCommon.NoticeParents;
namespace RegisterationSystem.SyncService
{
    /// <summary>
    /// GetDataList 的摘要说明
    /// </summary>
    public class GetDataList : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request["action"];
            switch (action.ToLower())
            {
                case "getschoolsstudentinfo":
                    GetSchoolsStudentInfo(context);
                    break;
                case "getschoollist":
                    GetSchoolList(context);
                    break;
                case "getschoolinfolist":
                    GetSchoolInfoList(context);
                    break;
                case "getundistributedstulist":
                    GetUndistributedStuList(context);
                    break;
                case "getstudentbyid":
                    GetStudentByID(context);
                    break;
                case "getschoolall":
                    GetSchoolAll(context);
                    break;
                case "getstudentbyschoolid":
                    GetStudentBySchoolID(context);
                    break;
                case "getschoolbyschoolid":
                    GetSchoolBySchoolID(context);
                    break;
                case "getnoticelist":
                    GetNoticeList(context);
                    break;
                case "getnoticebyid":
                    GetNoticeByID(context);
                    break;
                case "geteduall":
                    GetEduAll(context);
                    break;
                case "getcommlist":
                    GetCommList(context);
                    break;
                case "getcommlist1":
                    GetCommList1(context);
                    break;
                case "getcommlistaddall":
                    GetCommListAddAll(context);
                    break;
                case "getsysloglist":
                    GetsyslogList(context);
                    break;



                //
                case "getallstudentinfobidui":
                    GetAllStudentInfoBidui(context);
                    break;
                case "getallstudentinfolist":
                    GetAllStudentInfoList(context);
                    break;
                case "getallservicesdivisioninfolist":
                    GetAllServicesDivisionInfoList(context);
                    break;
                case "getschoolinfolistselect":
                    GetSchoolInfoListselect(context);
                    break;
                case "getbakdblist":
                    GetBakDBList(context);
                    break;
                //
                case "getstudentctinfo":
                    GetStudentCtInfo(context);
                    break;
                case "getallstudentcompareinfolist":
                    GetAllStudentCompareInfoList(context);
                    break;
                case "getallstudentcompareinfolist1":
                    GetAllStudentCompareInfoList1(context);
                    break;
                case "getallstudentmanagelist":
                    GetAllStudentManageList(context);
                    break;
                case "getstudentctbyid":
                    GetStudentCtByID(context);
                    break;
                case "getnoticeparentlist":
                    GetNoticeParentList(context);
                    break;
                case "getnoticeparentbyid":
                    GetNoticeParentByID(context);
                    break;
                case "getstudentnoticebyid":
                    getstudentnoticebyid(context);
                    break;
                case "getstudentnoticebyid2":
                    getstudentnoticebyid2(context);
                    break;
                case "getstudentcompareinfolistbyschid":
                    GetStudentCompareInfoListBySchId(context);
                    break;


                case "getallstudentnotice"://获取公告列表
                    getallstudentnotice(context);
                    break;

                    //幼儿园信息
                case "GetPreschoolsID":
                    GetPreschoolsID(context);
                    break;

            }
        }



        /// <summary>
        /// 返回指定目录的文件列表
        /// </summary>
        /// <param name="DirPath">要返回文件列表的父目录路径</param>
        /// <returns>字符串数组,如果异常则返回null</returns>
        public string[] GetFileList(string DirPath)
        {
            try
            {
                if (Directory.Exists(DirPath))
                {
                    return Directory.GetFiles(DirPath);
                }
                else
                {
                    return null;
                }
            }
            catch (Exception)
            {
                return null;
            }
        }
       
        public void getstudentnoticebyid(HttpContext context)
        {
            int id = Convert.ToInt32(context.Request["id"]);//得到公告ID
            //DataTable dtst = DBAction.GetDTFromSQL("Select * From NoticeReceive" + " where NoticeID=" + id);
            //if (dtst.Rows.Count < 1)
            //{
            //    return;
            //}
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //页面查询条件
            
            //where += " NoticeID=" + id;
            //初始查询条件
            string whereList = " NoticeID=" + id+" and Ext1=1";
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "id desc", SqlDbType.VarChar);
            rp.Add("Where", whereList, SqlDbType.VarChar);
            rp.Add("Tables", "NoticeReceive", SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            int totalCount = DBAction.GetDTFromSQL("select * from NoticeReceive where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();
        }
        //得到未阅读人的信息
        public void getstudentnoticebyid2(HttpContext context)
        {
            int id = Convert.ToInt32(context.Request["id"]);//得到公告ID
            //DataTable dtst = DBAction.GetDTFromSQL("Select * From NoticeReceive" + " where NoticeID=" + id);
            //if (dtst.Rows.Count < 1)
            //{
            //    return;
            //}
            //获取DataGrid设置每页显示数据行
            string ww = "1=1 ";
            string where = "NoticeID=" + id;
            DataTable dtst = DBAction.GetDTFromSQL("Select * From NoticeReceive where " + where);//找到该公告下的所有学生
            if (dtst.Rows.Count > 0)
            {
                for (int i = 0; i < dtst.Rows.Count; i++)
                {
                    ww += " and ID!=" + dtst.Rows[i]["StudentID"]+" ";
                }
            }
            DataTable dtt = DBAction.GetDTFromSQL("Select * From NoticeParents where ID=" + id);
            if (dtt.Rows.Count > 0)
            {
                ww += " and Status=2  and IsDelete=0 and SchID=" + dtt.Rows[0]["Schid"];//表示已经入学的学生
            }
            else
            {
                ww += " and Status=2  and IsDelete=0 ";//表示已经入学的学生
            }
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //页面查询条件

            //where += " NoticeID=" + id;
            //初始查询条件
            string whereList = " NoticeID=" + id + " and Ext1=0";
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "id desc", SqlDbType.VarChar);
            rp.Add("Where", ww, SqlDbType.VarChar);
            rp.Add("Tables", "Students", SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            int totalCount = DBAction.GetDTFromSQL("select * from Students where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();
        }
        //获取文件列表
        public void GetBakDBList(HttpContext context)
        {
            string BakPath = ConfigurationManager.AppSettings["RegisterationBakupPath"].ToString();
            DataTable dt = new DataTable();
            dt.Columns.Add("id", typeof(Int32));
            dt.Columns.Add("name", typeof(String));
            dt.Columns.Add("time", typeof(String));
            string[] FArr = GetFileList(BakPath);
            DateTime maxtime = File.GetLastWriteTime(FArr[0]);
            for (int n = 0; n < FArr.Length; n++)
            {
                string[] NArr = FArr[n].Split('\\');
                dt.Rows.Add(new Object[] { n, NArr[NArr.Length - 1], File.GetLastWriteTime(FArr[n]).ToString() });
                if (DateTime.Compare(File.GetLastWriteTime(FArr[n]), maxtime) > 0)
                {
                    maxtime = File.GetLastWriteTime(FArr[n]);
                }
            }
            string strJson = DBAction.DataTableToJson(dt);
            context.Response.Write(strJson);
            context.Response.End();
        }

        #region 返回社区列表
        /// <summary>
        /// 返回社区列表
        /// </summary>
        /// <param name="context"></param>
        void GetCommListAddAll(HttpContext context)
        {
            string parentID = context.Request.QueryString["parentID"];
            DataTable dt = DBAction.GetDTFromSQL("select id,name from Community where pid=" + parentID);
            DataRow dr = dt.NewRow();
            dr["id"] = -1;
            dr["name"] = "全部";
            dt.Rows.InsertAt(dr, 0);
            string strJson = DBAction.DataTableToJson(dt);
            context.Response.Write(strJson);
            context.Response.End();
        }
        /// <summary>
        /// 返回社区列表
        /// </summary>
        /// <param name="context"></param>
        void GetCommList(HttpContext context)
        {
            string parentID = context.Request.QueryString["parentID"];
            DataTable dt = DBAction.GetDTFromSQL("select * from Community where pid=" + parentID);

            DataRow dr = dt.NewRow();
            dr["id"] = -1;
            dr["name"] = "--请选择--";
            dt.Rows.InsertAt(dr, 0);


            string strJson = DBAction.DataTableToJson(dt);
            context.Response.Write(strJson);
            context.Response.End();
        }
        /// <summary>
        /// 返回社区列表
        /// </summary>
        /// <param name="context"></param>
        void GetCommList1(HttpContext context)
        {
            string parentID = context.Request.QueryString["parentID"];
            DataTable dt = DBAction.GetDTFromSQL("select * from Community where pid=" + parentID);

            


            string strJson = DBAction.DataTableToJson(dt);
            context.Response.Write(strJson);
            context.Response.End();
        }
        #endregion

        #region 返回所有教育局帐号
        /// <summary>
        /// 返回所有教育局帐号
        /// </summary>
        /// <param name="context"></param>
        void GetEduAll(HttpContext context)
        {
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "id", SqlDbType.VarChar);
            rp.Add("Where", "1=1", SqlDbType.VarChar);
            rp.Add("Tables", ETableName.EduAccount, SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            int totalCount = DBAction.GetDTFromSQL("select * from EduAccount where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();
        }
        #endregion

        #region 返回公告列表
        /// <summary>
        /// 返回公告列表
        /// </summary>
        /// <param name="context"></param>
        void GetNoticeList(HttpContext context)
        {
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            //页面查询条件
            string where = context.Request.Form["where"];
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "id desc", SqlDbType.VarChar);
            rp.Add("Where", where, SqlDbType.VarChar);
            rp.Add("Tables", ETableName.Notice, SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            int totalCount = DBAction.GetDTFromSQL("select * from Notice where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();
        }
        #endregion

        #region 返回教育端的学校发送公告列表
        /// <summary>
        /// 返回公告列表
        /// </summary>
        /// <param name="context"></param>
        void getallstudentnotice(HttpContext context)
        {
            int SchId = Convert.ToInt32(Cookies.Get("SchID"));
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            //页面查询条件
            string where = context.Request.Form["where"];
            if (where != "1=1")
            {
                string[] SelList = where.Split(new char[] { ',' }, StringSplitOptions.None);
                where = " 1=1 ";
                if (SelList[0] != "99")
                {
                    where += " and SchID =" + SelList[0] + "";//所属学校
                }
                
                if (SelList[1] != "" && SelList[2] != "")
                {
                    where += " and RTime between '" + SelList[1] + "' and '" + SelList[2] + "'";//出生日月
                }
            }


            //where += " and SchId=" + SchId;
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            //rp.Add("OrderBy", "SchId asc", SqlDbType.VarChar);
            rp.Add("OrderBy", "id desc", SqlDbType.VarChar);
            rp.Add("Where", where, SqlDbType.VarChar);
            //rp.Add("Tables", ETableName.NoticeParents, SqlDbType.VarChar);
            rp.Add("Tables", "NoticeParents", SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            int totalCount = DBAction.GetDTFromSQL("select * from NoticeParents where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();





        }
        #endregion

        #region 返回学校发送公告列表
        /// <summary>
        /// 返回公告列表
        /// </summary>
        /// <param name="context"></param>
        void GetNoticeParentList(HttpContext context)
        {
            int SchId = Convert.ToInt32(Cookies.Get("SchID"));
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            //页面查询条件
            string where = context.Request.Form["where"];
            where += " and SchId=" + SchId;
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            //rp.Add("OrderBy", "SchId asc", SqlDbType.VarChar);
            rp.Add("OrderBy", "id desc", SqlDbType.VarChar);
            rp.Add("Where", where, SqlDbType.VarChar);
            //rp.Add("Tables", ETableName.NoticeParents, SqlDbType.VarChar);
            rp.Add("Tables", "NoticeParents", SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            DataColumn dc1 = dt.Columns.Add("num", Type.GetType("System.Int32"));//给表插入一列
            dc1.DefaultValue = 0;
            dc1.ReadOnly = false;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                int nid = Convert.ToInt32(dt.Rows[i]["ID"].ToString());
                int sid = Convert.ToInt32(dt.Rows[i]["SchId"].ToString());
                int count = DBAction.GetDTFromSQL("select * from NoticeReceive where Schid=" + sid+" and NoticeID="+nid).Rows.Count;
                dt.Rows[i]["num"] = count;
            }


            int totalCount = DBAction.GetDTFromSQL("select * from NoticeParents where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();





        }
        #endregion

        #region 根据学校ID返回学校帐号
        /// <summary>
        /// 根据学校ID返回学校帐号
        /// </summary>
        /// <param name="context"></param>
        void GetSchoolBySchoolID(HttpContext context)
        {
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "id", SqlDbType.VarChar);
            rp.Add("Where", "SchID=" + Cookies.Get("SchID") + "", SqlDbType.VarChar);
            rp.Add("Tables", ETableName.SchoolAccount, SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            int totalCount = DBAction.GetDTFromSQL("select * from SchoolAccount where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();
        }
        #endregion

        #region 根据学校ID返回学生信息列表
        /// <summary>
        /// 根据学校ID返回学生信息列表
        /// </summary>
        /// <param name="context"></param>
        void GetStudentBySchoolID(HttpContext context)
        {
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //页面查询条件
            string where = context.Request.Form["where"];
            //初始查询条件
            // string whereList = "SchID =" + SchoolAccount.Current.SchID + "";
            string whereList = "SchID =" + Cookies.Get("SchID") + "";
            if (where != "1=1")
            {
                string[] SelList = where.Split(new char[] { ',' }, StringSplitOptions.None);
                where = " 1=1 ";
                if (SelList[0] != "")
                {
                    where += " and TrueName like '%" + SelList[0] + "%'";//学生姓名
                }
                if (SelList[1] != "")
                {
                    where += " and IDCardNumber like '%" + SelList[1] + "%'";//学生身份证
                }
                if (SelList[2] != "99")
                {
                    where += " and Sex =" + SelList[2] + "";//性别
                }
                if (SelList[3] != "99")
                {
                    where += " and SchID =" + SelList[3] + "";//所属学校
                }
                if (SelList[4] != "99")
                {
                    where += " and HouseAreaID =" + SelList[4] + "";//户口所在地
                }
                if (SelList[5] != "-1" && SelList[5] != "")
                {
                    where += " and ScommAreaID =" + SelList[5] + "";//住房社区
                }
                if (SelList[6] != "" && SelList[6] != "-1")
                {
                    where += " and XcommAreaID like '%" + SelList[6] + "%'";//住房小区
                }
                if (SelList[7] != "99")
                {
                    where += " and Level = " + SelList[7] + "";//学生等级
                }
                if (SelList[8] != "" && SelList[9] != "")
                {
                    where += " and Birthday between '" + SelList[8] + "' and '" + SelList[9] + "'";//出生日月
                }
                if (SelList[10] != "-1" && SelList[10] != "")
                {
                    where += " and pianid =" + SelList[10] + " ";//住房社区
                }
            }
            string typeID = context.Request.Form["typeid"];
            switch (typeID)
            {
                ////待审核学生
                case "0":
                    whereList += " and  IsMatured =1  and Status=1  and IsDelete=0 and  " + where;//进城务工
                    break;
                //初审通过学生
                case "1":
                    whereList += " and  IsMatured =1  and Status=2  and IsDelete=0 and " + where;
                    break;
                //被放弃学生
                case "2":
                    whereList += " and  IsMatured =1  and Status=3 and IsDelete=0 and " + where;
                    break;
                //被删除学生
                case "3":
                    whereList += " and Status>0 and IsDelete=1 and " + where;
                    break;
                //不足龄学生信息
                case "4":
                    whereList += " and IsMatured=0 and " + where;
                    break;
                default:
                    break;
            }


            if (typeID == "1")//为已经审核
            {
                string ww = "";
                ww = whereList + "  and  Ext2=0 ";//为手动分配
                //分页数小于一,返回
                if (pageSize < 1) { return; }
                RParams rp = new RParams();
                rp.Add("PageSize", pageSize, SqlDbType.Int);
                rp.Add("CurrentPage", currentPage, SqlDbType.Int);
                rp.Add("Columns", "*", SqlDbType.VarChar);
                rp.Add("OrderBy", "id desc", SqlDbType.VarChar);
                rp.Add("Where", ww, SqlDbType.VarChar);//先查找手动分配的
                rp.Add("Tables", ETableName.Students, SqlDbType.VarChar);
                rp.Add("GroupBy", "", SqlDbType.VarChar);
                //DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];

                DataTable dt = DBAction.GetDTFromSQL(" select *  from dbo.Students  where  " + ww);
                //DataTable dtn = SplitDataTable(dt, currentPage, pageSize);
                //string strJson = DBAction.DataTableToJson(dtn, true, dt.Rows.Count);
                //context.Response.Write(strJson);
                //context.Response.End();



                DataColumn dc = dt.Columns.Add("compareresult", Type.GetType("System.Int32"));
                dc.DefaultValue = 0;
                dc.ReadOnly = false;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dt.Rows[i]["compareresult"] = Compare(dt.Rows[i]);
                }

                ww = whereList + "  and Ext2=1  ";//为自动分配
                if (pageSize < 1) { return; }
                RParams rp1 = new RParams();
                rp1.Add("PageSize", pageSize, SqlDbType.Int);
                rp1.Add("CurrentPage", currentPage, SqlDbType.Int);
                rp1.Add("Columns", "*", SqlDbType.VarChar);
                rp1.Add("OrderBy", "id desc", SqlDbType.VarChar);
                rp1.Add("Where", ww, SqlDbType.VarChar);//自动分配
                rp1.Add("Tables", ETableName.Students, SqlDbType.VarChar);
                rp1.Add("GroupBy", "", SqlDbType.VarChar);
                //DataTable dt1 = DBAction.ExecSP(EStoredProc.sp_select_page, rp1).Tables[0];

                DataTable dt1 = DBAction.GetDTFromSQL(" select *  from dbo.Students  where  " + ww);
                //DataTable dtn = SplitDataTable(dt, currentPage, pageSize);
                //string strJson = DBAction.DataTableToJson(dtn, true, dt.Rows.Count);
                //context.Response.Write(strJson);
                //context.Response.End();

                DataColumn dc1 = dt1.Columns.Add("compareresult", Type.GetType("System.Int32"));
                dc1.DefaultValue = 0;
                dc1.ReadOnly = false;
                for (int i = 0; i < dt1.Rows.Count; i++)
                {
                    dt1.Rows[i]["compareresult"] = Compare(dt1.Rows[i]);
                }


                foreach (DataRow dr in dt1.Rows)
                {
                    dt.ImportRow(dr);
                }


                int totalCount2 = DBAction.GetDTFromSQL("select * from Students where " + rp.GetSqlParameter("Where").Value).Rows.Count;
                int totalCount1 = DBAction.GetDTFromSQL("select * from Students where " + rp1.GetSqlParameter("Where").Value).Rows.Count;
                int totalCount = totalCount1 + totalCount2;
                //string strJson = DBAction.DataTableToJson(dt, true, totalCount);
                //context.Response.Write(strJson);
                //context.Response.End();

                DataTable dtn = SplitDataTable(dt, currentPage, pageSize);
                string strJson = DBAction.DataTableToJson(dtn, true, totalCount);
                context.Response.Write(strJson);
                context.Response.End();
            }

            else
            {
                //分页数小于一,返回
                RParams rp = new RParams();
                rp.Add("PageSize", pageSize, SqlDbType.Int);
                rp.Add("CurrentPage", currentPage, SqlDbType.Int);
                rp.Add("Columns", "*", SqlDbType.VarChar);
                rp.Add("OrderBy", "id desc", SqlDbType.VarChar);
                rp.Add("Where", whereList, SqlDbType.VarChar);
                rp.Add("Tables", ETableName.Students, SqlDbType.VarChar);
                rp.Add("GroupBy", "", SqlDbType.VarChar);
                //DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];

                DataTable dt = DBAction.GetDTFromSQL(" select * from dbo.Students  where  " + whereList);


                DataColumn dc = dt.Columns.Add("compareresult", Type.GetType("System.Int32"));
                dc.DefaultValue = 0;
                dc.ReadOnly = false;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dt.Rows[i]["compareresult"] = Compare(dt.Rows[i]);
                }


                int totalCount = DBAction.GetDTFromSQL("select * from Students where " + rp.GetSqlParameter("Where").Value).Rows.Count;
                //string strJson = DBAction.DataTableToJson(dt, true, totalCount);
                //context.Response.Write(strJson);
                //context.Response.End();
                DataTable dtn = SplitDataTable(dt, currentPage, pageSize);
                string strJson = DBAction.DataTableToJson(dtn, true, totalCount);
                context.Response.Write(strJson);
                context.Response.End();
            }
        }
        #endregion

        #region 返回所有学校帐号
        /// <summary>
        /// 返回所有学校帐号
        /// </summary>
        /// <param name="context"></param>
        void GetSchoolAll(HttpContext context)
        {
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "SchID", SqlDbType.VarChar);
            rp.Add("Where", "1=1", SqlDbType.VarChar);
            rp.Add("Tables", ETableName.SchoolAccount, SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            int totalCount = DBAction.GetDTFromSQL("select * from SchoolAccount where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();
        }
        #endregion

        #region 根据ID获取公告信息(JSON)
        void GetNoticeByID(HttpContext context)
        {
            StringBuilder strBuilder = new StringBuilder("");
            int id = Convert.ToInt32(context.Request["id"]);
            Notice n = new Notice();
            if (n.GetHelpSubjectByID(id))
            {
                strBuilder.Append("{");
                strBuilder.Append("tile:'" + n.Tile + "',");
                strBuilder.Append("recrive:'" + n.Recrive + "',");
                strBuilder.Append("content:'" + n.Content + "',");
                strBuilder.Append("status:'" + Convert.ToInt32(n.Status) + "'");
                strBuilder.Append("}");
            }
            context.Response.Write(strBuilder);
            context.Response.End();
        }
        #endregion

        #region 根据ID获取学校公告信息(JSON)
        void GetNoticeParentByID(HttpContext context)
        {
            StringBuilder strBuilder = new StringBuilder("");
            int id = Convert.ToInt32(context.Request["id"]);
            NoticeParents n = new NoticeParents();
            if (n.GetHelpSubjectByID(id))
            {
                strBuilder.Append("{");
                strBuilder.Append("tile:'" + n.Title + "',");
                strBuilder.Append("recrive:'" + n.Recrive + "',");

                strBuilder.Append("content:'" + n.Content.Replace("\r\n"," ") + "',");
                strBuilder.Append("status:'" + Convert.ToInt32(n.Status) + "'");
                strBuilder.Append("}");
            }
            context.Response.Write(strBuilder);
            context.Response.End();
        }
        #endregion

        #region 根据ID获取学生信息(JSON)
        /// <summary>
        /// 根据ID获取学生信息
        /// </summary>
        /// <param name="context"></param>
        void GetStudentByID(HttpContext context)
        {
            StringBuilder strBuilder = new StringBuilder("");
            //学生编号
            int id = Convert.ToInt32(context.Request["id"]);
            StudentInfo s = new StudentInfo();
            if (s.GetStudentsByID(id))
            {
                strBuilder.Append("{");
                strBuilder.Append("name:'" + s.TrueName + "',");//学生姓名
                string sex = s.Sex == true ? "女" : "男"; //性别
                strBuilder.Append("sex:'" + sex + "',");
                strBuilder.Append("idcardnumber:'" + s.IDCardNumber + "',");//学生身份证
                strBuilder.Append("birthday:'" + s.Birthday.ToString("yyyy-MM-dd") + "',");//出生年月
                strBuilder.Append("hobby:'" + s.Hobby + "',");                              //兴趣爱好
                strBuilder.Append("HouseIngoingTime:'" + s.HouseIngoingTime + "',");         //户口迁入时间
                strBuilder.Append("HousingOccupancyTime:'" + s.HousingOccupancyTime + "',"); //住房入住时间
                strBuilder.Append("PermanentAddress:'" + s.PermanentAddress + "',");         //户籍地址
                strBuilder.Append("deletereason:'" + s.DeleteReason + "',");                 //删除原因
                strBuilder.Append("firstguardianname:'" + s.FirstGuardianName + "',");      //第一监护人姓名
                strBuilder.Append("firstguardianunit:'" + s.FirstGuardianUnit + "',");      //第一监护人工作单位
                strBuilder.Append("firstguardianphone:'" + s.FirstGuardianPhone + "',");    //第一监护人联系电话
                strBuilder.Append("firstrelationship:'" + s.FirstRelationship + "',");      //第一监护人和他的关系
                strBuilder.Append("secguardianname:'" + s.SecGuardianName + "',");          //第二监护人姓名
                strBuilder.Append("secguardianunit:'" + s.SecGuardianUnit + "',");          //第二监护人工作单位
                strBuilder.Append("secrelationship:'" + s.SecRelationship + "',");          //第二监护人和他的关系
                strBuilder.Append("phonestatus:'" + Convert.ToInt32(s.PhoneStatus) + "',"); //电话回访状态(0未回访1回访)
                strBuilder.Append("status:'" + Convert.ToInt32(s.Status) + "',");           //信息状态(0未分配1已分配2初审通过)
                strBuilder.Append("phonestatustext:'" + s.PhoneStatusText + "',");          //电话回访反馈说明
                strBuilder.Append("pcommname:'" + s.pianname + "',");
                strBuilder.Append("scommname:'" + s.ScommName + "',");                      //社区名称
                strBuilder.Append("xcommname:'" + s.XcommName + "',");                      //小区名称
                
                strBuilder.Append("level:'" + s.Level + "',");                              //学生等级(0A 1B 2C)
                strBuilder.Append("housenumber:'" + s.HouseNumber + "',");                  //门牌号
                strBuilder.Append("housecard:'" + s.HouseCard + "',");                      //房产号
                strBuilder.Append("houseareaid:'" + s.HouseAreaID + "',"); //户口所在地(0经济技术开发区1市内其它区2省内市外、外省外市)
                strBuilder.Append("secguardianphone:'" + s.SecGuardianPhone + "'");         //第二监护人联系电话
                strBuilder.Append("}");
            }
            context.Response.Write(strBuilder);
            context.Response.End();
        }
        #endregion

        public void GetStudentCtByID(HttpContext context)
        {
            int id = Convert.ToInt32(context.Request["id"]);
            DataTable dtst = DBAction.GetDTFromSQL("Select * From " + ETableName.Students + " where ID=" + id);
            if (dtst.Rows.Count < 1)
            {
                return;
            }
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //页面查询条件
            string where = context.Request.Form["where"];
            if (!string.IsNullOrEmpty(where))
            {
                where += " and CtName='" + dtst.Rows[0]["TrueName"] + "'";
            }
            else
            {
                where += "CtName='" + dtst.Rows[0]["TrueName"] + "'";
            }
            //初始查询条件
            string whereList = where;
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "id desc", SqlDbType.VarChar);
            rp.Add("Where", whereList, SqlDbType.VarChar);
            rp.Add("Tables", ETableName.ContrastInfo, SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            int totalCount = DBAction.GetDTFromSQL("select * from " + ETableName.ContrastInfo + "  where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();

        }

        #region 获取教育局状态学生列表
        /// <summary>
        /// 获取教育局状态学生列表
        /// </summary>
        /// <param name="context"></param>
        void GetUndistributedStuList(HttpContext context)
        {
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //页面查询条件
            string where = context.Request.Form["where"];
            if (where != "1=1")
            {
                string[] SelList = where.Split(new char[] { ',' }, StringSplitOptions.None);
                where = " 1=1 ";
                if (SelList[0] != "")
                {
                    where += " and TrueName like '%" + SelList[0] + "%'";//学生姓名
                }
                if (SelList[1] != "")
                {
                    where += " and IDCardNumber like '%" + SelList[1] + "%'";//学生身份证
                }
                if (SelList[2] != "99")
                {
                    where += " and Sex =" + SelList[2] + "";//性别
                }
                if (SelList[3] != "99")
                {
                    where += " and SchID =" + SelList[3] + "";//所属学校
                }
                if (SelList[4] != "99")
                {
                    where += " and HouseAreaID =" + SelList[4] + "";//户口所在地
                }
                if (SelList[5] != "-1" && SelList[5] != "")
                {
                    where += " and ScommAreaID =" + SelList[5] + "";//住房社区
                }
                if (SelList[6] != "" && SelList[6] != "-1")
                {
                    where += " and XcommAreaID like '%" + SelList[6] + "%'";//住房小区
                }
                if (SelList[7] != "99")
                {
                    where += " and Level = " + SelList[7] + "";//学生等级
                }
                if (SelList[8] != "" && SelList[9] != "")
                {
                    where += " and Birthday between '" + SelList[8] + "' and '" + SelList[9] + "'";//出生日月
                }
                if (SelList[10] != "-1" && SelList[10] != "")
                {
                    where += " and pianid =" + SelList[10] + " ";//住房社区
                }
            }
            //初始查询条件
            string whereList = "";
            string typeID = context.Request.Form["typeid"];
            switch (typeID)
            {
                //待分配学生信息
                case "0":
                    //足龄、未分配、无学校、不是删除状态
                    //未分配、无学校、不是删除状态（不要求足龄）
                    whereList = " Status=0 and SchID=0 and IsDelete=0  and IsMatured =1 and  " + where;//足龄或者不是代录
                    break;
                //已分配学生信息
                case "1":
                    whereList = " IsMatured =1  and   Status=1 and SchID>0 and IsDelete=0  and " + where;
                    break;
                //待审核学生信息
                case "2":
                    whereList = " IsMatured =1  and   Status=1 and SchID>0 and IsDelete=0  and " + where;
                    break;
                //已审核学生信息
                case "3":
                    whereList = " IsMatured =1  and    Status=2 and SchID>0 and IsDelete=0 and " + where;
                    break;
                //已删除学生信息
                case "4":
                    whereList = " IsDelete=1 and " + where;
                    break;
                //不足龄学生信息
                case "5":
                    whereList = " IsMatured =0 and " + where;
                    break;
                //特招学生信息
                case "6":
                    whereList = " IsMatured =1  and Status=2 and SchID>0 and IsDelete=0 and Level=3 and " + where;
                    break;
                //被放弃学生信息
                case "7":
                    whereList = " IsMatured =1 and Status=3 and IsDelete=0 and " + where;
                    break;
                //市内其它区且无房产学生信息
                case "8":
                    whereList = " IsMatured =1 and Status=0 and SchID=0 and HouseAreaID=1 and IsDelete=0 and IsSelf=1 and " + where;
                    break;
                default:
                    break;
            }


            if (typeID == "3")//为已经审核
            {
                string ww = "";
                ww = whereList + "  and  Ext2=0 ";//为手动分配
                //分页数小于一,返回
                if (pageSize < 1) { return; }
                RParams rp = new RParams();
                rp.Add("PageSize", pageSize, SqlDbType.Int);
                rp.Add("CurrentPage", currentPage, SqlDbType.Int);
                rp.Add("Columns", "*", SqlDbType.VarChar);
                rp.Add("OrderBy", "id desc", SqlDbType.VarChar);
                rp.Add("Where", ww, SqlDbType.VarChar);//先查找手动分配的
                rp.Add("Tables", ETableName.Students, SqlDbType.VarChar);
                rp.Add("GroupBy", "", SqlDbType.VarChar);
                DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];

                DataColumn dc = dt.Columns.Add("compareresult", Type.GetType("System.Int32"));
                dc.DefaultValue = 0;
                dc.ReadOnly = false;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dt.Rows[i]["compareresult"] = Compare(dt.Rows[i]);
                }

                ww = whereList + "  and Ext2=1  ";//为自动分配
                if (pageSize < 1) { return; }
                RParams rp1 = new RParams();
                rp1.Add("PageSize", pageSize, SqlDbType.Int);
                rp1.Add("CurrentPage", currentPage, SqlDbType.Int);
                rp1.Add("Columns", "*", SqlDbType.VarChar);
                rp1.Add("OrderBy", "id desc", SqlDbType.VarChar);
                rp1.Add("Where", ww, SqlDbType.VarChar);//自动分配
                rp1.Add("Tables", ETableName.Students, SqlDbType.VarChar);
                rp1.Add("GroupBy", "", SqlDbType.VarChar);
                DataTable dt1 = DBAction.ExecSP(EStoredProc.sp_select_page, rp1).Tables[0];

                DataColumn dc1 = dt1.Columns.Add("compareresult", Type.GetType("System.Int32"));
                dc1.DefaultValue = 0;
                dc1.ReadOnly = false;
                for (int i = 0; i < dt1.Rows.Count; i++)
                {
                    dt1.Rows[i]["compareresult"] = Compare(dt1.Rows[i]);
                }


                foreach (DataRow dr in dt1.Rows)
                {
                    dt.ImportRow(dr);
                }


                int totalCount2 = DBAction.GetDTFromSQL("select * from Students where " + rp.GetSqlParameter("Where").Value).Rows.Count;
                int totalCount1 = DBAction.GetDTFromSQL("select * from Students where " + rp1.GetSqlParameter("Where").Value).Rows.Count;
                int totalCount = totalCount1 + totalCount2;
                string strJson = DBAction.DataTableToJson(dt, true, totalCount);
                context.Response.Write(strJson);
                context.Response.End();
            }

            else
            {

                //分页数小于一,返回
                if (pageSize < 1) { return; }
                RParams rp = new RParams();
                rp.Add("PageSize", pageSize, SqlDbType.Int);
                rp.Add("CurrentPage", currentPage, SqlDbType.Int);
                rp.Add("Columns", "*", SqlDbType.VarChar);
                rp.Add("OrderBy", "level,id desc", SqlDbType.VarChar);
                rp.Add("Where", whereList, SqlDbType.VarChar);
                rp.Add("Tables", ETableName.Students, SqlDbType.VarChar);
                rp.Add("GroupBy", "", SqlDbType.VarChar);
                DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];

                DataColumn dc = dt.Columns.Add("compareresult", Type.GetType("System.Int32"));
                dc.DefaultValue = 0;
                dc.ReadOnly = false;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dt.Rows[i]["compareresult"] = Compare(dt.Rows[i]);
                }


                int totalCount = DBAction.GetDTFromSQL("select * from Students where " + rp.GetSqlParameter("Where").Value).Rows.Count;
                string strJson = DBAction.DataTableToJson(dt, true, totalCount);
                context.Response.Write(strJson);
                context.Response.End();
            }
        }
        
        #endregion

        public int Compare(DataRow dr)
        {
            int res = 0;
            DataTable dt = new DataTable();
            dt = DBAction.GetDTFromSQL("select * from Students where ID='" + dr["ID"].ToString().Trim() + "'");
            if (dt.Rows.Count > 0)
            {
                int count = 0;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if(dt.Rows[i]["Ext4"].ToString()=="0")//为特殊人才
                    {
                        res=2;
                        break;
                    }
                    else if (dt.Rows[i]["Ext2"].ToString() == "0")//为手动分配
                    {    
                        res = 0;
                        break;
                    }
                    else if (dt.Rows[i]["Ext2"].ToString() == "1")
                    {
                        res = 1;
                        break;
                    }
                    
                    else
                    {
                        count++;
                    }
                }
                if (count == dt.Rows.Count)
                {
                    res = 3;
                }
            }
            else
            {
                res = 1;
            }
            return res;

        }

        #region 获取教育局学生管理列表
        /// <summary>
        /// 获取教育局学生管理列表
        /// </summary>
        /// <param name="context"></param>
        void GetAllStudentManageList(HttpContext context)
        {
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //页面查询条件
            string where = context.Request.Form["where"];
            if (where != "1=1")
            {
                string[] SelList = where.Split(new char[] { ',' }, StringSplitOptions.None);
                where = " 1=1 ";
                if (!string.IsNullOrEmpty(SelList[0].Trim()))
                {
                    where += " and TrueName like '%" + SelList[0] + "%'";//学生姓名
                }
                if (!string.IsNullOrEmpty(SelList[1].Trim()))
                {
                    where += " and IDCardNumber like '%" + SelList[1] + "%'";//身份证
                }
            }
            //初始查询条件
            string whereList = where;
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "level,id desc", SqlDbType.VarChar);
            rp.Add("Where", whereList, SqlDbType.VarChar);
            rp.Add("Tables", ETableName.Students, SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            int totalCount = DBAction.GetDTFromSQL("select * from Students  where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();





            //DataTable dt = DBAction.GetDTFromSQL("select *,Preschools.Name as pcname from Students inner join dbo.Preschools on Students.PreschoolsID=dbo.Preschools.ID");
            //int totalCount = DBAction.GetDTFromSQL("select * from Students  where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            //string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            //context.Response.Write(strJson);
            //context.Response.End();
            //DataTable dtn = SplitDataTable(dt, currentPage, pageSize);
            //string strJson = DBAction.DataTableToJson(dtn, true, totalCount);
            //context.Response.Write(strJson);
            //context.Response.End();


        }
        #endregion


        #region 分页

        public static DataTable SplitDataTable(DataTable dt, int PageIndex, int PageSize)
        {
            if (PageIndex == 0)
                return dt;
            DataTable newdt = dt.Clone();
            int rowbegin = (PageIndex - 1) * PageSize;
            int rowend = PageIndex * PageSize;
            if (rowbegin >= dt.Rows.Count)
                return newdt;
            if (rowend > dt.Rows.Count)
                rowend = dt.Rows.Count;
            for (int i = rowbegin; i <= rowend - 1; i++)
            {
                DataRow newdr = newdt.NewRow();
                DataRow dr = dt.Rows[i];
                foreach (DataColumn column in dt.Columns)
                {
                    newdr[column.ColumnName] = dr[column.ColumnName];
                }
                newdt.Rows.Add(newdr);
            }
            return newdt;
        }
        #endregion

        #region 获取教育局状态学生列表
        /// <summary>
        /// 获取教育局状态学生列表
        /// </summary>
        /// <param name="context"></param>
        void GetAllStudentInfoList(HttpContext context)
        {
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //页面查询条件
            string where = context.Request.Form["where"];
            if (where != "1=1")
            {
                string[] SelList = where.Split(new char[] { ',' }, StringSplitOptions.None);
                where = " 1=1 ";
                if (SelList[0] != "-1" && SelList[0] != "")
                {
                    where += " and ScommAreaID =" + SelList[0] + "";//住房社区
                }
                if (SelList[1] != "" && SelList[1] != "-1")
                {
                    where += " and XcommAreaID like '%" + SelList[1] + "%'";//住房小区
                }
                if (SelList[2] != "" && SelList[2] != "-1")
                {
                    where += " and pianid =" + SelList[2] + " ";//住房片区
                }
            }
            //初始查询条件
            string whereList = " IsMatured =1 and (SchID>0 or (SchID=0 and HouseAreaID!=1)) and " + where;
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "ScommName,XcommName,level,id desc", SqlDbType.VarChar);
            rp.Add("Where", whereList, SqlDbType.VarChar);
            rp.Add("Tables", ETableName.Students, SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            int totalCount = DBAction.GetDTFromSQL("select * from Students  where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();
        }
        #endregion

        #region 获取教育局状态学生对比信息列表
        /// <summary>
        /// 获取教育局状态学生列表
        /// </summary>
        /// <param name="context"></param>
        void GetAllStudentCompareInfoList(HttpContext context)
        {
            int table = Convert.ToInt32(context.Request["table"]);
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            DataTable dt = new DataTable();
            //页面查询条件
            string where = context.Request.Form["where"];
            if (where != "1=1")
            {
                string[] SelList = where.Split(new char[] { ',' }, StringSplitOptions.None);
                where = " 1=1 ";
                if (SelList[0] != "-1" && SelList[0] != "")
                {
                    where += " and ScommAreaID =" + SelList[0] + "";//住房社区
                }
                if (SelList[1] != "" && SelList[1] != "-1")
                {
                    where += " and XcommAreaID like '%" + SelList[1] + "%'";//住房小区
                }
                if (SelList[2] != "-1" && SelList[2] != "")
                {
                    where += " and pianid =" + SelList[2] + "";//住房社区
                }
            }
            //初始查询条件
            string whereList = where + " and  IDCardNumber!=''";
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "ScommName,XcommName,level,id desc", SqlDbType.VarChar);
            rp.Add("Where", whereList, SqlDbType.VarChar);
            rp.Add("Tables", ETableName.Students, SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            DataColumn dc = dt.Columns.Add("compareresult", Type.GetType("System.Int32"));
            dc.DefaultValue = 0;
            dc.ReadOnly = false;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["compareresult"] = CompareStudent(dt.Rows[i]);
            }


            DataTable newdata = dt.Clone();
            object[] obj = new object[newdata.Columns.Count];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["compareresult"].ToString() != "0")
                {
                    dt.Rows[i].ItemArray.CopyTo(obj, 0);
                    newdata.Rows.Add(obj);
                }
            }

            int totalCount = DBAction.GetDTFromSQL("select * from Students where IDCardNumber!=''  and  " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();
        }
        #endregion


        #region 获取教育局状态学生对比信息列表
        /// <summary>
        /// 获取教育局状态学生列表，按照学校划分来区分
        /// </summary>
        /// <param name="context"></param>
        void GetAllStudentCompareInfoList1(HttpContext context)
        {
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //页面查询条件
            string where = context.Request.Form["where"];
            if (where != "1=1")
            {
                string[] SelList = where.Split(new char[] { ',' }, StringSplitOptions.None);
                where = " 1=1 ";
                if (SelList[0] != "999999" && SelList[0] != "")
                {
                    where += " and SchID =" + SelList[0] + "";//学校
                }
                //if (SelList[1] != "" && SelList[1] != "-1")
                //{
                //    where += " and XcommAreaID like '%" + SelList[1] + "%'";//住房小区
                //}
            }
            //初始查询条件
            string whereList = where;
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "ScommName,XcommName,level,id desc", SqlDbType.VarChar);
            rp.Add("Where", whereList, SqlDbType.VarChar);
            rp.Add("Tables", ETableName.Students, SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            DataColumn dc = dt.Columns.Add("compareresult", Type.GetType("System.Int32"));
            dc.DefaultValue = 0;
            dc.ReadOnly = false;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["compareresult"] = CompareStudent(dt.Rows[i]);
            }
            int totalCount = DBAction.GetDTFromSQL("select * from Students  where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();
        }
        #endregion


        #region 获取教育局状态学生对比信息列表
        /// <summary>
        /// 获取教育局状态学生列表
        /// </summary>
        /// <param name="context"></param>
        public void GetStudentCompareInfoListBySchId(HttpContext context)
        {
            int table = Convert.ToInt32(context.Request["table"]);
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            DataTable dt = new DataTable();
            //页面查询条件
            string where = context.Request.Form["where"];
            if (where != "1=1")
            {
                string[] SelList = where.Split(new char[] { ',' }, StringSplitOptions.None);
                where = " 1=1 ";
                if (SelList[0] != "-1" && SelList[0] != "")
                {
                    where += " and ScommAreaID =" + SelList[0] + "";//住房社区
                }
                if (SelList[1] != "" && SelList[1] != "-1")
                {
                    where += " and XcommAreaID like '%" + SelList[1] + "%'";//住房小区
                }
                if (SelList[2] != "-1" && SelList[2] != "")
                {
                    where += " and pianid =" + SelList[2] + "";//住房社区
                }
            }
            //初始查询条件

            if (!string.IsNullOrEmpty(Cookies.Get("SchID")))
            {
                where += " and SchID=" + Cookies.Get("SchID").ToString().Trim();
            }
            string whereList = where + " and  IDCardNumber!=''";
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "ScommName,XcommName,level,id desc", SqlDbType.VarChar);
            rp.Add("Where", whereList, SqlDbType.VarChar);
            rp.Add("Tables", ETableName.Students, SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            DataColumn dc = dt.Columns.Add("compareresult", Type.GetType("System.Int32"));
            dc.DefaultValue = 0;
            dc.ReadOnly = false;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["compareresult"] = CompareStudent(dt.Rows[i]);
            }


            DataTable newdata = dt.Clone();
            object[] obj = new object[newdata.Columns.Count];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["compareresult"].ToString() != "0")
                {
                    dt.Rows[i].ItemArray.CopyTo(obj, 0);
                    newdata.Rows.Add(obj);
                }
            }

            int totalCount = DBAction.GetDTFromSQL("select * from Students where IDCardNumber!=''  and  " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();
        }
        #endregion

        /// <summary>
        /// 学生信息比较
        /// </summary>
        /// <param name="dr"></param>
        /// <returns>0:完全匹配；1：公安系统不存在；2：只有户籍不匹配；3：出生日期或者性别不匹配</returns>
        public int CompareStudent(DataRow dr)
        {
            int res = 0;
            DataTable dt = new DataTable();
            dt = DBAction.GetDTFromSQL("select * from ContrastInfo where CtName='" + dr["TrueName"].ToString().Trim() + "'");
            if (dt.Rows.Count > 0)
            {
                int count = 0;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dr["Birthday"].ToString().Trim() == dt.Rows[i]["CtBirthday"].ToString().Trim() && (bool)dr["Sex"] == (bool)dt.Rows[i]["CtSex"])
                    {
                        if (dr["PermanentAddress"].ToString().Trim() == dt.Rows[i]["CtAddress"].ToString().Trim())
                        {
                            res = 0;
                        }
                        else
                        {
                            res = 2;
                        }
                        break;
                    }
                    else
                    {
                        count++;
                    }
                }
                if (count == dt.Rows.Count)
                {
                    res = 3;
                }
            }
            else
            {
                res = 1;
            }
            return res;
        }

        #region 获取教育局状态学生列表
        /// <summary>
        /// 获取教育局状态学生列表
        /// </summary>
        /// <param name="context"></param>
        void GetAllStudentInfoBidui(HttpContext context)
        {
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //页面查询条件
            string where1 = context.Request.Form["where"];
            if (where1 != "1=1")
            {
                ////初始查询条件
                string where = "HouseAreaID=0 and ID not in(select students.ID from studentinfos,students where HouseAreaID=0 and studentinfos.Name=students.TrueName and studentinfos.Birthday=students.Birthday and studentinfos.Sex=students.Sex)";
                string whereList = " IsMatured =1 and " + where;
                //分页数小于一,返回
                if (pageSize < 1) { return; }
                RParams rp = new RParams();
                rp.Add("PageSize", pageSize, SqlDbType.Int);
                rp.Add("CurrentPage", currentPage, SqlDbType.Int);
                rp.Add("Columns", "*", SqlDbType.VarChar);
                rp.Add("OrderBy", "level,id desc", SqlDbType.VarChar);
                rp.Add("Where", whereList, SqlDbType.VarChar);
                rp.Add("Tables", ETableName.Students, SqlDbType.VarChar);
                rp.Add("GroupBy", "", SqlDbType.VarChar);
                DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
                int totalCount = DBAction.GetDTFromSQL("select * from Students where " + rp.GetSqlParameter("Where").Value).Rows.Count;
                string strJson = DBAction.DataTableToJson(dt, true, totalCount);
                context.Response.Write(strJson);
                context.Response.End();
            }
        }
        #endregion

        #region 获取教育局状态学生列表
        /// <summary>
        /// 获取教育局状态学生列表
        /// </summary>
        /// <param name="context"></param>
        void GetAllServicesDivisionInfoList(HttpContext context)
        {
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //页面查询条件
            //////string where = context.Request.Form["where"];
            //////if (where != "1=1")
            //////{
            //////    string[] SelList = where.Split(new char[] { ',' }, StringSplitOptions.None);
            //////    where = " 1=1 ";
            //////    if (SelList[0] != "999" && SelList[0] != "")
            //////    {
            //////        where += " and ScommAreaID =" + SelList[0] + "";//住房社区
            //////    }
            //////    if (SelList[1] != "" && SelList[1] != "999")
            //////    {
            //////        where += " and XcommAreaID like '%" + SelList[1] + "%'";//住房小区
            //////    }
            //////}
            //初始查询条件
            string whereList = "";
            if (context.Request.Form["SchID"] != "999999")
            {
                string SchID = context.Request.Form["SchID"];
                whereList = " IsMatured =1 and SchID>0 and SchID=" + Convert.ToInt32(SchID) + " and ServicesDivision!=0 ";
            }
            else if (context.Request.Form["SchID"] == "999999")
            {
                whereList = " IsMatured =1 and SchID>0 and ServicesDivision!=0 ";
            }
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "level,id desc", SqlDbType.VarChar);
            rp.Add("Where", whereList, SqlDbType.VarChar);
            rp.Add("Tables", ETableName.Students, SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            int totalCount = DBAction.GetDTFromSQL("select * from Students where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();
        }
        #endregion
        #region 各校招生信息统计
        /// <summary>
        /// 各校招生信息统计
        /// </summary>
        /// <param name="context"></param>
        void GetSchoolsStudentInfo(HttpContext context)
        {
            //初始化DT
            DataTable dt = new DataTable();
            dt.Columns.Add("name");//学校名称
            dt.Columns.Add("count");//计划招生数
            dt.Columns.Add("csycount");//初审通过
            dt.Columns.Add("csncount");//初审不通过
            dt.Columns.Add("nstatus");//未审核
            dt.Columns.Add("matured");//不足龄
            //获取所有学校
            using (DataTable schDt = DBAction.GetDTFromSQL("select * from SchoolInfo"))
            {
                if (schDt.Rows.Count > 0)
                {
                    //遍历学校
                    for (int i = 0; i < schDt.Rows.Count; i++)
                    {
                        //初始化DT行
                        DataRow dr = dt.NewRow();
                        dr["name"] = schDt.Rows[i]["name"].ToString();//学校名称
                        dr["count"] = schDt.Rows[i]["count"].ToString();//计划招生数
                        dr["csycount"] = DBAction.GetDTFromSQL("select id from Students where SchID=" + schDt.Rows[i]["id"] + " and Status =2 and IsDelete=0").Rows.Count.ToString();//初审通过
                        dr["csncount"] = DBAction.GetDTFromSQL("select id from Students where SchID=" + schDt.Rows[i]["id"] + " and Status =3 and IsDelete=0").Rows.Count.ToString();//初审不通过
                        dr["nstatus"] = DBAction.GetDTFromSQL("select id from Students where SchID=" + schDt.Rows[i]["id"] + " and Status =1 and IsMatured =1 and IsDelete=0").Rows.Count.ToString();//未审核
                        dr["matured"] = DBAction.GetDTFromSQL("select id from Students where SchID=" + schDt.Rows[i]["id"] + " and IsMatured =0 and IsDelete=0").Rows.Count.ToString();//不足龄
                        //添加到DT中
                        dt.Rows.Add(dr);
                    }
                }
            }
            //把DT转换为JSON
            string strJson = DBAction.DataTableToJson(dt, true, dt.Rows.Count);
            context.Response.Write(strJson);
            context.Response.End();
        }
        #endregion

        #region 获取学校列表
        /// <summary>
        /// 获取学校列表
        /// </summary>
        /// <param name="context"></param>
        void GetSchoolList(HttpContext context)
        {
            using (DataTable dt = DBAction.GetDTFromSQL("select * from SchoolInfo"))
            {
                if (dt.Rows.Count > 0)
                {
                    //把DT转换为JSON
                    string strJson = DBAction.DataTableToJson(dt, true, dt.Rows.Count);
                    context.Response.Write(strJson);
                    context.Response.End();
                }
            }
        }
        #endregion

        #region 获取学校下拉框列表
        /// <summary>
        /// 获取学校下拉框列表
        /// </summary>
        /// <param name="context"></param>
        void GetSchoolInfoList(HttpContext context)
        {
            using (DataTable dt = DBAction.GetDTFromSQL("select * from SchoolInfo"))
            {
                if (dt.Rows.Count > 0)
                {
                    //把DT转换为JSON
                    string strJson = DBAction.DataTableToJson(dt);
                    context.Response.Write(strJson);
                    context.Response.End();
                }
            }
        }
        #endregion

        #region 获取学校下拉框列表
        /// <summary>
        /// 获取学校下拉框列表用于服务划分时候的按学校查询
        /// </summary>
        /// <param name="context"></param>
        void GetSchoolInfoListselect(HttpContext context)
        {
            using (DataTable dt = DBAction.GetDTFromSQL("select id,name from SchoolInfo"))
            {
                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.NewRow();
                    dr["id"] = "999999";
                    dr["name"] = "全部";
                    dt.Rows.InsertAt(dr, 0);
                    //把DT转换为JSON
                    string strJson = DBAction.DataTableToJson(dt);
                    context.Response.Write(strJson);
                    context.Response.End();
                }
            }
        }
        #endregion

        #region 获取学校列表
        /// <summary>
        /// 获取学校列表
        /// </summary>
        /// <param name="context"></param>
        void GetStudentCtInfo(HttpContext context)
        {
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //页面查询条件
            string where = context.Request.Form["where"];
            if (where != "1=1")
            {
                string[] SelList = where.Split(new char[] { ',' }, StringSplitOptions.None);
                where = " 1=1 ";
                if (!string.IsNullOrEmpty(SelList[0].Trim()))
                {
                    where += " and CtName like '%" + SelList[0].Trim() + "%'";//姓名
                }
            }
            //初始查询条件
            string whereList = where;
            //分页数小于一,返回
            if (pageSize < 1) { return; }
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "id desc", SqlDbType.VarChar);
            rp.Add("Where", whereList, SqlDbType.VarChar);
            rp.Add("Tables", "ContrastInfo", SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            int totalCount = DBAction.GetDTFromSQL("select * from ContrastInfo where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();
        }
        #endregion

        /// <summary>
        /// 操作日志管理
        /// </summary>
        /// <param name="context"></param>
        void GetsyslogList(HttpContext context)
        {
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //页面查询条件
            string where = context.Request.Form["where"];
            if (where != "1=1")
            {
                string[] SelList = where.Split(new char[] { ',' }, StringSplitOptions.None);
                where = " 1=1 ";
                if (SelList[0] != "")
                {
                    where += " and Operator like '%" + SelList[0] + "%'";//操作员
                }
                if (SelList[1] != "" && SelList[2] != "")
                {
                    where += " and LogTime between '" + SelList[1] + "' and '" + SelList[2] + "'";//操作时间
                }
                if (SelList[3] != "")
                {
                    where += " and Ip like '%" + SelList[3] + "%'";//IP
                }
                if (SelList[4] != "全部")
                {
                    where += " and TypeName ='" + SelList[4] + "'";//日志类型
                }
            }

            //分页数小于一,返回
            if (pageSize < 1) { return; }
            RParams rp = new RParams();
            rp.Add("PageSize", pageSize, SqlDbType.Int);
            rp.Add("CurrentPage", currentPage, SqlDbType.Int);
            rp.Add("Columns", "*", SqlDbType.VarChar);
            rp.Add("OrderBy", "LogTime desc", SqlDbType.VarChar);
            rp.Add("Where", where, SqlDbType.VarChar);
            rp.Add("Tables", "Sys_Log", SqlDbType.VarChar);
            rp.Add("GroupBy", "", SqlDbType.VarChar);
            DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
            int totalCount = DBAction.GetDTFromSQL("select * from Sys_Log where " + rp.GetSqlParameter("Where").Value).Rows.Count;
            string strJson = DBAction.DataTableToJson(dt, true, totalCount);
            context.Response.Write(strJson);
            context.Response.End();
        }

        /// <summary>
        /// 幼儿园信息
        /// </summary>
        /// <param name="context"></param>
        void GetPreschoolsID(HttpContext context)
        {
            //获取DataGrid设置每页显示数据行
            int pageSize = context.Request.Form["rows"] != "" ? Convert.ToInt32(context.Request.Form["rows"]) : 0;
            //获取DataGrid设置显示页码
            int currentPage = context.Request.Form["page"] != "" ? Convert.ToInt32(context.Request.Form["page"]) : 0;
            //页面查询条件
            string where = context.Request.Form["where"];

            string whereList = "SchID =" + Cookies.Get("SchID") + "";
            if (where != "1=1")
            {
              
            }

                string ww = "";
                ww = whereList + "  and  Ext2=0 ";//为手动分配
                //分页数小于一,返回
                if (pageSize < 1) { return; }
                RParams rp = new RParams();
                rp.Add("PageSize", pageSize, SqlDbType.Int);
                rp.Add("CurrentPage", currentPage, SqlDbType.Int);
                rp.Add("Columns", "*", SqlDbType.VarChar);
                rp.Add("OrderBy", "ID desc", SqlDbType.VarChar);
                rp.Add("Where", "", SqlDbType.VarChar);//先查找手动分配的
                rp.Add("Tables", "Preschools", SqlDbType.VarChar);
                rp.Add("GroupBy", "", SqlDbType.VarChar);
                DataTable dt = DBAction.ExecSP(EStoredProc.sp_select_page, rp).Tables[0];
                int totalCount = DBAction.GetDTFromSQL("select * from Preschools where " + rp.GetSqlParameter("Where").Value).Rows.Count;
                string strJson = DBAction.DataTableToJson(dt, true, totalCount);
                context.Response.Write(strJson);
                context.Response.End();
        }
        /// <summary>
        /// 内容是否仅一次使用
        /// </summary>
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}